﻿/****************************** Module Header ******************************\
 * Module Name:  mxDbParameter.cs
 * Module Version:  1.0.0 (2014-3-14)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This class is used to extension collection instance's method.  It supplies 
 * useful extension methods, such as ToString(), FetchString() and so on.
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;

namespace UCL.Data
{
    public static class mxDbParameter
    {
        /// <summary>
        /// 将数组格式的DbParameter转为Dictionary格式的DbParameter字典
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static Dictionary<string, object> ToDictionary(this IList<DbParameter> parameters)
        {
            Dictionary<string, object> dict = new Dictionary<string, object>();
            foreach (DbParameter para in parameters)
            {
                dict[para.ParameterName] = para.Value;
            }
            return dict;
        }

        public static string ToValueText(this IList<DbParameter> paras)
        {
            StringBuilder sb = new StringBuilder();
            foreach (DbParameter para in paras)
            {
                sb.AppendFormat("{0},", para.Value);
            }
            return sb.ToString();
        }
    }
}
